< previous page page_229 next page >

Page 229
I know what you're thinking: Why is &H7FFFFFFF the largest number that a Long variable can hold? What about &HFFFFFFFF?
Try it and see what happens.
The result is 1.
You see, a Visual Basic Long variable is a signed variable, which means that the high bit indicates that the number is negative. If Visual Basic supported a 32-bit unsigned variable, loading that variable with &HFFFFFFFF would result in the number 4294967294.
So, the signed value 1 corresponds to the unsigned value 4294967294. Both are stored identically in memory as &HFFFFFFFFthe only difference between them is the way the data is interpreted by the software.
When you look at the following constant definition,
#define USER_MAXSTORAGE_UNLIMITED ((unsigned long)-1L)
you'll notice that before the 1 is the term ''(unsigned long)." What does this mean? It's called a "cast." When a type appears in parentheses before a number or variable in the C language, it tells the compiler to interpret the data according to that type. So, even though the number shown is 1 (the L indicates that it's a 32-bit 1), the cast tells the compiler that the programmer really intends this to be interpreted as an unsigned value, which in this case is 4294967294.
From our point of view as Visual Basic programmers, we don't really care how the data is interpreted by the C compiler. All we care about is making sure that we load the variable with the correct value. The correct value in this case is &HFFFFFFFF, and the easiest way to load a Visual Basic Long variable with that value is to set it to 1. The correct declaration is therefore
Private Const USER_MAXSTORAGE_UNLIMITED = -1
And Now the Array . . .
The usri2_logon_hours field of the USER_INFO2 structure can optionally be set to a pointer to a 21-byte (168-bit) array. In our original solution, we used Long variables for all the fields in the USER_INFO2 structure. Numeric data was handled by direct assignment of the numeric data to the Long variable. Strings were handled by loading the Long variable with the address of a Unicode string obtained using the StrPtr operator. Is it possible to set the usri2_logon_hours field to a pointer to a 21-byte array in a similar manner? Absolutely.
First, create the byte array as follows:
Dim HourList(20) As Byte

 
< previous page page_229 next page >